home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-08-25 | 12.1 KB | 466 lines | [TEXT/CWIE] |
-
-
- #include "EditorUtilities.h"
-
- #include "CFileRefEditorWindow.h"
-
- const ResType kSelectFileB = 'slfB';
- const ResType kRemoveFileRefB = 'rmvB';
- const ResType kFileNameET = 'fnmE';
- const ResType kFileTypeET = 'ftpE';
- const ResType kFileCreatorET = 'fcrE';
- //const ResType kCreationDateET = 'fcdE';
- const ResType kMediaTypePM = 'mptP';
- const ResType kFilePathET = 'fphE';
-
- #define kUnknownMedia 0 // Net install setup on CD-ROM or hard disk. Use relative path from Upgrader application.
- #define kFloppyDiskMedia 1 // Multiple floppy disk set. Use full path starting with floppy volume name.
- #define kCDROMDiskMedia 2 // Multiple CD-ROM disk set. Use full path starting with CD-ROM volume name.
-
-
- SInt32 DoEditFileRef( SInt16 inFileRefNum, SInt16 &inFileRefRsrcID, Boolean inSharedFileRef )
- {
- // Return values: 0 = Changes accepted, 1 = Canceled, no changes made, < 0 = Internal error, no changes mad
- SInt32 result = -1;
-
- SInt16 savedResFile = CurResFile();
- UseResFile( inFileRefNum );
-
- try
- {
- CFileRefEditorWindow* theEditorWindow = new CFileRefEditorWindow( inFileRefNum, inFileRefRsrcID, inSharedFileRef );
-
- if( inFileRefRsrcID == 0 )
- theEditorWindow->mFileRefRsrcID = GetUniqueIDForResType( inFileRefNum, 'flrf' );
-
- result = theEditorWindow->DoEdit();
-
- delete theEditorWindow;
-
- if( result == 0 || result == 2 )
- inFileRefRsrcID = theEditorWindow->mFileRefRsrcID;
-
- }
- catch( OSErr theErr )
- {
- ;
- }
-
- UseResFile( savedResFile );
-
- return result;
-
- }
-
- void GetPathFromFileRef( SInt16 inFileRefNum, SInt16 inFileRefRsrcID, Str255 outFilePathForDisplay )
- {
-
- SInt16 savedResFile = CurResFile();
- UseResFile( inFileRefNum );
-
- try
- {
- outFilePathForDisplay[0] = 0;
-
- Handle theRsrcHandle = Get1Resource( 'flrf', inFileRefRsrcID );
-
- if( theRsrcHandle )
- {
- TRsrcHandle* theRsrcStream = new TRsrcHandle( theRsrcHandle );
- SignalIf_(theRsrcStream == nil);
-
- if( theRsrcStream->ReadShort() == 0)
- {
- // No flags at the moment
- theRsrcStream->ReadShort();
-
- // Set Media Type Popup
- theRsrcStream->ReadShort();
-
- // Set Type
- theRsrcStream->ReadLong();
-
- // Set Creator
- theRsrcStream->ReadLong();
-
- // Set Creation Date
- theRsrcStream->ReadLong();
-
- // Set File Path name
- theRsrcStream->ReadPStrIntoStr255( outFilePathForDisplay );
-
- // Set File name
- Str255 theFileName;
- theRsrcStream->ReadPStrIntoStr255( theFileName );
- PStrConcat( outFilePathForDisplay, theFileName );
-
- }
-
- delete theRsrcStream;
-
- }
-
-
- }
- catch( OSErr theErr )
- {
- ;
- }
-
- UseResFile( savedResFile );
- }
-
- // ---------------------------------------------------------------------------
- // • CFileRefEditorWindow
- // ---------------------------------------------------------------------------
- CFileRefEditorWindow::CFileRefEditorWindow( SInt16 inFileRefNum, SInt16 inFileRefRsrcID, Boolean inSharedFileRef )
- : StDialogHandler(133, NULL), mFileRefNum(inFileRefNum), mFileRefRsrcID(inFileRefRsrcID), mSharedFileRef(inSharedFileRef)
- {
- }
-
- // ---------------------------------------------------------------------------
- // • ~CFileRefEditorWindow
- // ---------------------------------------------------------------------------
- CFileRefEditorWindow::~CFileRefEditorWindow()
- {
- }
-
-
- SInt32 CFileRefEditorWindow::DoEdit()
- {
-
- LWindow *theDialog = GetDialog();
-
- this->LoadWindowFromFile();
-
- theDialog->Show();
-
- LEditField* theField = (LEditField*) mDialog->FindPaneByID(kFileNameET);
- SignalIf_(theField == nil);
- theDialog->SetLatentSub(theField);
-
- SInt32 result = -1;
-
- while (true) {
- MessageT hitMessage = DoDialog();
-
- if (hitMessage == msg_Cancel) {
- result = 1;
- break;
-
- } else if (hitMessage == kRemoveFileRefB) {
-
- if( mSharedFileRef ) {
- mFileRefRsrcID = 0;
- result = 0;
- }
- else {
- Handle theRsrcHandle = Get1Resource( 'flrf', mFileRefRsrcID );
- if( theRsrcHandle ) {
- RemoveResource( theRsrcHandle );
- DisposeHandle( theRsrcHandle );
- }
- mFileRefRsrcID = 0;
- result = 2;
- }
- break;
-
- } else if (hitMessage == kSelectFileB) {
-
- SFTypeList typeList;
- StandardFileReply reply;
- StandardGetFile( NULL, -1, typeList, &reply );
-
- if( reply.sfGood )
- {
-
- // Set Media Type Popup
- LStdPopupMenu* thePopupMenu = (LStdPopupMenu*) mDialog->FindPaneByID(kMediaTypePM);
- SignalIf_(thePopupMenu == nil);
-
-
- Str255 thePathStr;
- ResType theFileType;
- ResType theFileCreator;
- UInt32 theFileCreationDate;
- GetInfoFromFSSpec( &reply.sfFile, mFileRefNum, thePopupMenu->GetValue() > 1, thePathStr, theFileType, theFileCreator, theFileCreationDate );
-
- // Set Type
- LEditField* theField = (LEditField*) mDialog->FindPaneByID(kFileTypeET);
- SignalIf_(theField == nil);
- LStr255 aType(theFileType);
- theField->SetDescriptor( StringPtr(aType) );
-
- // Set Creator
- theField = (LEditField*) mDialog->FindPaneByID(kFileCreatorET);
- SignalIf_(theField == nil);
- LStr255 anotherType(theFileCreator);
- theField->SetDescriptor( StringPtr(anotherType) );
- /*
- // Set Creation Date
- theField = (LEditField*) mDialog->FindPaneByID(kCreationDateET);
- SignalIf_(theField == nil);
- Str255 theDateStr;
- DateString( theFileCreationDate, longDate, theDateStr, nil);
- theField->SetDescriptor( theDateStr );
- */
- // Set File Path name
- theField = (LEditField*) mDialog->FindPaneByID(kFilePathET);
- SignalIf_(theField == nil);
- theField->SetDescriptor( thePathStr );
-
- // Set File name
- theField = (LEditField*) mDialog->FindPaneByID(kFileNameET);
- SignalIf_(theField == nil);
- theField->SetDescriptor( reply.sfFile.name );
- }
-
- } else if (hitMessage == msg_OK) {
- this->SaveWindowToFile();
- result = 0;
- break;
- }
- }
-
- return result;
- }
-
-
- void CFileRefEditorWindow::SaveWindowToFile()
- {
-
- TRsrcHandle* theRsrcStream = new TRsrcHandle();
- SignalIf_(theRsrcStream == nil);
-
- theRsrcStream->AppendShort( 0 );
- theRsrcStream->AppendShort( 0 );
-
- // Set Media Type Popup
- LStdPopupMenu* thePopupMenu = (LStdPopupMenu*) mDialog->FindPaneByID(kMediaTypePM);
- SignalIf_(thePopupMenu == nil);
- theRsrcStream->AppendShort( thePopupMenu->GetValue() - 1 );
-
- // Set Type
- LEditField* theField = (LEditField*) mDialog->FindPaneByID(kFileTypeET);
- SignalIf_(theField == nil);
- LStr255 theTypeStr;
- theField->GetDescriptor( theTypeStr );
- if( theTypeStr[0] == 0 )
- theRsrcStream->AppendLong( 0 );
- else
- theRsrcStream->AppendLong( FourCharCode( theTypeStr ) );
-
- // Set Creator
- theField = (LEditField*) mDialog->FindPaneByID(kFileCreatorET);
- SignalIf_(theField == nil);
- LStr255 theCrtrStr;
- theField->GetDescriptor( theCrtrStr );
- if( theCrtrStr[0] == 0 )
- theRsrcStream->AppendLong( 0 );
- else
- theRsrcStream->AppendLong( FourCharCode( theCrtrStr ) );
-
- /*
- // Set Creation Date
- theField = (LEditField*) mDialog->FindPaneByID(kCreationDateET);
- SignalIf_(theField == nil);
- Str255 theDateStr;
- theField->GetDescriptor( theDateStr );
- DateCacheRecord theCache;
- long lengthUsed;
- LongDateRec dateTime;
- InitDateCache( &theCache );
- StringToDate( (char*)theDateStr, theDateStr[0], &theCache, &lengthUsed, &dateTime);
- StringToTime( (char*)theDateStr, theDateStr[0], &theCache, &lengthUsed, &dateTime);
- unsigned long dateInSecs;
- DateToSeconds( &(dateTime.od.oldDate), &dateInSecs );
- theRsrcStream->AppendLong( dateInSecs );
- */
- theRsrcStream->AppendLong( 0 ); // Always set Creation Date to 0 for now.
-
- // Set File Path name
- theField = (LEditField*) mDialog->FindPaneByID(kFilePathET);
- SignalIf_(theField == nil);
- Str255 theFilePath;
- theField->GetDescriptor( theFilePath );
- if( theFilePath[0] == 0 ) {
- theFilePath[0] = 1;
- theFilePath[1] = ':';
- }
- theRsrcStream->AppendStr255( theFilePath );
-
- // Set File name
- theField = (LEditField*) mDialog->FindPaneByID(kFileNameET);
- SignalIf_(theField == nil);
- Str255 theFileName;
- theField->GetDescriptor( theFileName );
- theRsrcStream->AppendStr255( theFileName );
-
- theRsrcStream->Write( mFileRefNum, 'flrf', mFileRefRsrcID );
-
- delete theRsrcStream;
- }
-
-
- void CFileRefEditorWindow::LoadWindowFromFile()
- {
-
- Handle theRsrcHandle = Get1Resource( 'flrf', mFileRefRsrcID );
-
- if( theRsrcHandle )
- {
- TRsrcHandle* theRsrcStream = new TRsrcHandle( theRsrcHandle );
- SignalIf_(theRsrcStream == nil);
-
- if( theRsrcStream->ReadShort() == 0)
- {
-
- theRsrcStream->ReadShort(); // No flags at the moment
-
- // Set Media Type Popup
- LStdPopupMenu* thePopupMenu = (LStdPopupMenu*) mDialog->FindPaneByID(kMediaTypePM);
- SignalIf_(thePopupMenu == nil);
- thePopupMenu->SetValue( theRsrcStream->ReadShort() + 1 );
-
- // Set Type
- LEditField* theField = (LEditField*) mDialog->FindPaneByID(kFileTypeET);
- SignalIf_(theField == nil);
- LStr255 aType((ResType)theRsrcStream->ReadLong());
- theField->SetDescriptor( StringPtr(aType) );
-
- // Set Creator
- theField = (LEditField*) mDialog->FindPaneByID(kFileCreatorET);
- SignalIf_(theField == nil);
- LStr255 anotherType((ResType)theRsrcStream->ReadLong());
- theField->SetDescriptor( StringPtr(anotherType) );
-
- theRsrcStream->ReadLong(); // Ignore Creation Date for now
- /*
- // Set Creation Date
- theField = (LEditField*) mDialog->FindPaneByID(kCreationDateET);
- SignalIf_(theField == nil);
- Str255 theDateStr;
- DateString( theRsrcStream->ReadLong(), longDate, theDateStr, nil);
- theField->SetDescriptor( theDateStr );
- */
- // Set File Path name
- theField = (LEditField*) mDialog->FindPaneByID(kFilePathET);
- SignalIf_(theField == nil);
- Str255 theFilePath;
- theRsrcStream->ReadPStrIntoStr255( theFilePath );
- theField->SetDescriptor( theFilePath );
-
- // Set File name
- theField = (LEditField*) mDialog->FindPaneByID(kFileNameET);
- SignalIf_(theField == nil);
- Str255 theFileName;
- theRsrcStream->ReadPStrIntoStr255( theFileName );
- theField->SetDescriptor( theFileName );
-
- }
-
- delete theRsrcStream;
-
- }
- }
-
-
-
- void CFileRefEditorWindow::GetInfoFromFSSpec( FSSpec* inFSSpec, SInt16 inDocRefNum, Boolean inFullPath, Str255 outPathStr, ResType &outFileType, ResType &outFileCreator, UInt32 &outFileCreationDate )
- {
-
-
- CInfoPBRec cInfo;
- HFileInfo* hfipb = (HFileInfo *)&cInfo;
-
- // we need to get this file's CInfoPBRec so that we know
- // its size, mod date, creation date...
- hfipb->ioCompletion = nil;
- hfipb->ioNamePtr = inFSSpec->name;
- hfipb->ioVRefNum = inFSSpec->vRefNum;
- hfipb->ioDirID = inFSSpec->parID;
- hfipb->ioFDirIndex = 0;
-
- if( ::PBGetCatInfoSync(&cInfo) == noErr )
- {
- outFileType = hfipb->ioFlFndrInfo.fdType;
- outFileCreator = hfipb->ioFlFndrInfo.fdCreator;
- outFileCreationDate = hfipb->ioFlCrDat;
- BuildSrcPath( inFSSpec, inDocRefNum, inFullPath, outPathStr );
- }
-
- }
-
-
- // ---------------------------------------------------------------------------
- // • BuildSrcPath
- // ---------------------------------------------------------------------------
-
- void CFileRefEditorWindow::BuildSrcPath( FSSpec* inFSSpec, SInt16 inDocRefNum, Boolean inFullPath, Str255 outPathStr )
- {
-
- // Get the directory of the document, to use in determining a partial path
- SInt32 partialPathDirID = 0;
-
- if( ! inFullPath )
- {
- FCBPBRec paramBlock;
- Str255 fName;
-
- paramBlock.ioNamePtr = fName;
- paramBlock.ioFCBIndx = 0;
- paramBlock.ioRefNum = inDocRefNum;
-
- if ( PBGetFCBInfoSync( ¶mBlock ) == noErr)
- partialPathDirID = paramBlock.ioFCBParID;
- }
-
- // Build the path string
- CInfoPBRec cInfo;
- DirInfo* dipb = (DirInfo *)&cInfo;
- char colon = ':';
- Str255 theStr;
- SInt32 theVol = inFSSpec->vRefNum;
- SInt32 theDirID = inFSSpec->parID;
- OSErr aErr = noErr;
- Boolean first = true;
-
- theStr[0] = 0;
-
- outPathStr[0] = 0;
-
- LStr255 buildStr;
-
- do
- {
- dipb->ioCompletion = nil;
- dipb->ioNamePtr = theStr;
- dipb->ioVRefNum = theVol;
- dipb->ioDrDirID = theDirID;
- dipb->ioFDirIndex = -1;
- aErr = ::PBGetCatInfoSync(&cInfo);
- if (aErr == noErr)
- {
- if( !inFullPath && theDirID == partialPathDirID )
- break;
-
- buildStr = colon + buildStr;
-
- buildStr = theStr + buildStr;
- theStr[0] = 0;
-
- }
- theDirID = dipb->ioDrParID;
- first = false;
-
- }
- while (aErr == noErr);
-
- if( !inFullPath )
- buildStr = colon + buildStr;
-
- LString::CopyPStr(StringPtr(buildStr), outPathStr, sizeof(Str255));
-
- }
-
-